<template>
  <el-dialog :title="!dataForm.studentName ? '新增' : dataForm.studentName+'体检报告'" :close-on-click-modal="false" :visible.sync="visible" fullscreen>
    <el-divider content-position="center">基本信息</el-divider>
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px">
      <el-row :gutter="10">
        <el-col :span="6">
          <el-form-item label="学生姓名" prop="studentName">
            <el-input v-model="dataForm.studentName" placeholder="学生姓名" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="性别" prop="gender">
            <el-select v-model="dataForm.gender" placeholder="请选择" disabled>
              <el-option label="男" :value="0"></el-option>
              <el-option label="女" :value="1"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="出生日期" prop="birthDay">
            <el-date-picker v-model="dataForm.birthDay" type="date" placeholder="选择日期时间" value-format="yyyy-MM-dd"
              disabled></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label="就读学校" prop="schoolId">
            <el-select v-model="studentData.schoolId" clearable filterable default-first-option placeholder="输入学校名字查找"
              disabled>
              <el-option v-for="item in schoolOptions" :value="item.id" :label="item.schoolName" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="就读年级" prop="gradeId">
            <el-select v-model="studentData.gradeId" disabled>
              <el-option v-for="item in gradeOptions" :value="item.id" :label="item.gradeName" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="就读班级" prop="classId">
            <el-select v-model="studentData.classId" disabled>
              <el-option v-for="item in classOptions" :value="item.id" :label="item.className" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="民族" prop="nationality">
            <el-select v-model="dataForm.nationality" disabled>
              <el-option v-for="item in nationalList" :value="item.id" :label="item.name" :key="item.id"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="户口类型" prop="accountType">
            <el-select v-model="dataForm.accountType" placeholder="请选择" disabled>
              <el-option label="乡村" :value="1"></el-option>
              <el-option label="城市" :value="0"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="家庭住址" prop="address">
            <el-input v-model="dataForm.address" placeholder="家庭住址" readonly></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="身高(cm)" prop="height">
            <el-input v-model="dataForm.height" placeholder="身高" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="体重(kg)" prop="weight">
            <el-input v-model="dataForm.weight" placeholder="体重" readonly></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item label="发育评价" prop="heightEvaluation">
        <el-input v-model="dataForm.heightEvaluation" placeholder="身高评价" readonly></el-input>
      </el-form-item>
      <!--    <el-form-item label="体重评价" prop="weightEvaluation">-->
      <!--      <el-input v-model="dataForm.weightEvaluation" placeholder="体重评价"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="营养评价" prop="nutritionalEvaluation">-->
      <!--      <el-input v-model="dataForm.nutritionalEvaluation" placeholder="营养评价"></el-input>-->
      <!--    </el-form-item>-->
      <el-form-item label="视力评价" prop="visionEvaluation">
        <el-input v-model="dataForm.visionEvaluation" placeholder="视力评价" readonly></el-input>
      </el-form-item>
      <!--    <el-form-item label="创建时间" prop="createTime">-->
      <!--      <el-input v-model="dataForm.createTime" placeholder="创建时间"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="更新时间" prop="updateTime">-->
      <!--      <el-input v-model="dataForm.updateTime" placeholder="更新时间"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="创建用户id" prop="createUser">-->
      <!--      <el-input v-model="dataForm.createUser" placeholder="创建用户id"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="修改用户id" prop="updateUser">-->
      <!--      <el-input v-model="dataForm.updateUser" placeholder="修改用户id"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="单位id" prop="unitId">-->
      <!--      <el-input v-model="dataForm.unitId" placeholder="单位id"></el-input>-->
      <!--    </el-form-item>-->
      <!--    <el-form-item label="租户id" prop="tenantId">-->
      <!--      <el-input v-model="dataForm.tenantId" placeholder="租户id"></el-input>-->
      <!--    </el-form-item>-->
    </el-form>
    <el-divider content-position="center">详情</el-divider>
    <el-table :data="dataList" border>
      <el-table-column prop="bust" label="胸围"></el-table-column>
      <el-table-column prop="vitalCapacity" label="肺活量"></el-table-column>
      <el-table-column prop="bloodPressureLeft" label="血压左"></el-table-column>
      <el-table-column prop="bloodPressureRight" label="血压右"></el-table-column>
      <el-table-column prop="pulse" label="脉搏"></el-table-column>
      <el-table-column prop="visionLeft" label="视力左"></el-table-column>
      <el-table-column prop="visionRight" label="视力右"></el-table-column>
      <el-table-column prop="correctVisionLeft" label="矫正视力左"></el-table-column>
      <el-table-column prop="correctVisionRight" label="矫正视力右"></el-table-column>
    </el-table>
    <el-table :data="dataList" border>
      <el-table-column prop="paiLeft" label="排左"></el-table-column>
      <el-table-column prop="paiRight" label="排右"></el-table-column>
      <el-table-column prop="hearingLeft" label="听力左"></el-table-column>
      <el-table-column prop="hearingRight" label="听力右"></el-table-column>
      <el-table-column prop="trachoma" label="沙眼"></el-table-column>
      <el-table-column prop="colorVision" label="色觉"></el-table-column>
      <el-table-column prop="rhinopathy" label="鼻病"></el-table-column>
    </el-table>
    <el-table :data="dataList" border>
      <el-table-column prop="permanentTeethCariesD" label="恒牙龋齿D"></el-table-column>
      <el-table-column prop="permanentTeethCariesM" label="恒牙龋齿M"></el-table-column>
      <el-table-column prop="permanentTeethCariesF" label="恒牙龋齿F"></el-table-column>
      <el-table-column prop="deciduousToothDecayD" label="乳牙龋齿D"></el-table-column>
      <el-table-column prop="deciduousToothDecayM" label="乳牙龋齿M"></el-table-column>
      <el-table-column prop="deciduousToothDecayF" label="乳牙龋齿F"></el-table-column>
      <el-table-column prop="priodontalDisease" label="牙周疾病"></el-table-column>
    </el-table>
    <el-table :data="dataList" border>
      <el-table-column prop="heart" label="心"></el-table-column>
      <el-table-column prop="lung" label="肺"></el-table-column>
      <el-table-column prop="liver" label="肝"></el-table-column>
      <el-table-column prop="spleen" label="脾"></el-table-column>
      <el-table-column prop="spine" label="脊柱"></el-table-column>
      <el-table-column prop="flatFeet" label="平足"></el-table-column>
      <el-table-column prop="limbs" label="四肢"></el-table-column>
      <el-table-column prop="skin" label="皮肤"></el-table-column>
    </el-table>
    <el-table :data="dataList" border>
      <el-table-column prop="infectiousDisease" label="传染病"></el-table-column>
      <el-table-column prop="chestXRay" label="胸透"></el-table-column>
      <el-table-column prop="fecalExamination" label="粪检"></el-table-column>
      <el-table-column prop="hemoglobin" label="血色素(血红蛋白)"></el-table-column>
      <el-table-column prop="hepatitis" label="肝炎"></el-table-column>
      <el-table-column prop="tuberculosis" label="肺结核"></el-table-column>
    </el-table>
    <el-table :data="dataList" border>
      <el-table-column prop="congenitalHeartDisease" label="先天性心脏病"></el-table-column>
      <el-table-column prop="nephritis" label="肾炎"></el-table-column>
      <el-table-column prop="rheumatism" label="风湿病"></el-table-column>
      <el-table-column prop="alanineAminotransferase" label="谷丙转氨酶"></el-table-column>
      <el-table-column prop="totalBilirubin" label="总胆红素"></el-table-column>
      <el-table-column prop="otherInformation" label="其他病症"></el-table-column>
    </el-table>
    <!--<span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">关闭</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>-->
  </el-dialog>
</template>

<script>
  import {
    getPvmMedicalReportById,
    addPvmMedicalReportObj,
    putPvmMedicalReportObj,
    getChildrenEvaluate
  } from '@/api/pvm/pvmmedicalreport'
  import { fetchNationalList } from '@/api/admin/national'
  import {
    getClassOptions,
    getSchoolList,
    getSchoolObj
  } from "@/api/pvm/school"
  import { getGradeBySchoolId } from "@/api/pvm/grade"

  export default {
    data() {
      // 自定义检查基本信息是否填写
      var validateMsg = (rule, value, callback) => {
        if (!this.dataForm.height && !this.dataForm.width && !this.dataForm.birthDay && !this.dataForm.gender) {
          callback(new Error('请输入基本信息'));
        } else {
          callback();
        }
      };
      return {
        visible: false,
        dataForm: {
          id: 0,
          studentName: '',
          birthDay: '',
          gender: '',
          nationality: '',
          accountType: '',
          address: '',
          height: '',
          weight: '',
          bust: '',
          vitalCapacity: '',
          bloodPressureLeft: '',
          bloodPressureRight: '',
          pulse: '',
          visionLeft: '',
          visionRight: '',
          correctVisionLeft: '',
          correctVisionRight: '',
          paiLeft: '',
          paiRight: '',
          hearingLeft: '',
          hearingRight: '',
          trachoma: '',
          colorVision: '',
          rhinopathy: '',
          permanentTeethCariesD: '',
          permanentTeethCariesM: '',
          permanentTeethCariesF: '',
          deciduousToothDecayD: '',
          deciduousToothDecayM: '',
          deciduousToothDecayF: '',
          priodontalDisease: '',
          heart: '',
          lung: '',
          liver: '',
          spleen: '',
          spine: '',
          flatFeet: '',
          limbs: '',
          skin: '',
          infectiousDisease: '',
          chestXRay: '',
          fecalExamination: '',
          hemoglobin: '',
          hepatitis: '',
          tuberculosis: '',
          congenitalHeartDisease: '',
          nephritis: '',
          rheumatism: '',
          alanineAminotransferase: '',
          totalBilirubin: '',
          otherInformation: '',
          heightEvaluation: '',
          weightEvaluation: '',
          nutritionalEvaluation: '',
          visionEvaluation: '',
          pvmStudent: {},
          studentId: '',
          // createTime: '',
          // updateTime: '',
          // createUser: '',
          // updateUser: '',
          // unitId: '',
          // tenantId: ''
        },
        studentData: {},
        nationalList: [],
        dataList: [],
        schoolOptions: [],
        gradeOptions: [],
        classOptions: [],
        dataListLoading: false
      }
    },
    created() {
      this.getNationalList()
    },
    methods: {
      // 获取民族列表
      getNationalList() {
        fetchNationalList({
          current: 1,
          size: 100
        }).then(response => {
          if(response.data.code == '0'){
            this.nationalList = response.data.data.records
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
      init(id, dataList) {
        this.dataForm.id = id || 0
        this.visible = true
        this.dataList[0] = dataList
        this.getSchoolOptions()
        this.$nextTick(() => {
          //this.getNationalList()
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            //this.dataListLoading = true
            getPvmMedicalReportById(this.dataForm.id).then(response => {
              if(response.data.code == '0'){
                this.dataForm = response.data.data
                this.studentData = this.dataForm.pvmStudent
                this.$set(this.dataForm, 'nationality', Number(this.dataForm.nationality))
                getSchoolObj(this.studentData.schoolId).then(res => {
                  if(res.data.code == '0'){
                    this.$set(this.studentData, 'schoolName', res.data.data.schoolName)
                    this.$set(this.studentData, 'schoolCode', res.data.data.schoolCode)
                  }else{
                    this.$message.error(res.data.msg)
                  }
                })
                getGradeBySchoolId(this.studentData.schoolId).then(res => {
                  if(res.data.code == '0'){
                    this.gradeOptions = res.data.data
                  }else{
                    this.$message.error(res.data.msg)
                  }
                })
                getClassOptions(this.studentData.schoolId, this.studentData.gradeId).then(res => {
                  if(res.data.code == '0'){
                    this.classOptions = res.data.data
                  }else{
                    this.$message.error(res.data.msg)
                  }
                })
              }else{
                this.$message.error(response.data.msg)
              }
            })
          }
        })
      },
      // 查询学校列表
      getSchoolOptions() {
        getSchoolList().then(response => {
          if(response.data.code == '0'){
            this.schoolOptions = response.data.data
          }else{
            this.$message.error(response.data.msg)
          }
        })
      },
    }
  }
</script>
